import showConfig from '../resources/showConfig.js'
export default {
  props: {
    bpmnModel: {//model对象
      type: Object,
      required: true
    },
    element: {//当前环节模型
      type: Object,
      required: true
    },
    // categorys: {
    //   type: Array,
    //   default: () => []
    // },
  },
  watch: {
    'form.id': function(val) {
      this.updateProperties({ id: val })
    },
    'form.name': function(val) {
      this.updateProperties({ name: val })
    },
    'form.documentation': function(val) {
      if (!val) {
        this.updateProperties({ documentation: [] })
        return
      }
      const documentationElement = this.bpmnModel.get('moddle').create('bpmn:Documentation', { text: val })
      this.updateProperties({ documentation: [documentationElement] })
    }
  },
  methods: {
    updateProperties(properties) {
      const modeling = this.bpmnModel.get('modeling')
      modeling.updateProperties(this.element, properties)
    }
  },
  computed: {
    elementType() {
      const bizObj = this.element.businessObject
      return bizObj.eventDefinitions
        ? bizObj.eventDefinitions[0].$type
        : bizObj.$type
    },
    showConfig() {
      return showConfig[this.elementType] || {}
    }
  }
}
